﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using FlexiGridHelper;
using System.Data;
using System.Web.Script.Serialization;
using Golf.Model;
namespace Golf.WebUI.HttpHandler.Basicdata
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary> 
    public class OrderStatus : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            JavaScriptSerializer js = new JavaScriptSerializer();
            List<Test> test = new List<Test>();
            for (int i = 0; i < 50; i++)
            {
                Test T = new Test();
                T.Id = i;
                T.UserName = "张三" + i;
                T.UserEmail = "zhangsan@aa.com" + i;
                T.UserCode = "邮编" + i;
                T.UserQQ = i + "";
                test.Add(T);
            }
            //实例化页面信息类，获取页面传来的参数。该类是FlexiGridHelper中定义的类，封装了很多功能需要的数据
            PageView pageView = new PageView(context);
            //获取分页后的数据集
            List<Test> pagerStudentList = test.Skip((pageView.PageIndex - 1) * pageView.PageSize).Take(pageView.PageSize).ToList();
            //构建表格
            DataTable dt = new DataTable();
            //构建列
            //注意：第一列必须是数据库的主键列  
            DataColumn dc0 = new DataColumn("Id", typeof(string));
            DataColumn dc1 = new DataColumn("UserName", typeof(string));
            DataColumn dc2 = new DataColumn("UserEmail", typeof(string));
            DataColumn dc3 = new DataColumn("UserCode", typeof(string));
            DataColumn dc4 = new DataColumn("UserQQ", typeof(string));
            //把构建的列添加到数据表中
            dt.Columns.AddRange(new DataColumn[] { dc0, dc1, dc2, dc3, dc4 });
            //填充数据
            foreach (var item in pagerStudentList)
            {
                //新建行，注意是dt.NewRow();而不是new DataRow();
                DataRow dr = dt.NewRow();
                dr["ID"] = item.Id;
                dr["UserName"] = item.UserName;
                dr["UserEmail"] = item.UserEmail;
                dr["UserCode"] = item.UserCode;
                dr["UserQQ"] = item.UserQQ;
                dt.Rows.Add(dr);
            }
            //调用FlexiGrid数据格式转换方法
            context.Response.Write(js.Serialize(new GetDataHelper().GetFlexiGridData(pageView, dt, test.Count)));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
